package com.hnkywl.sts.action.organ;

import com.hnkywl.sts.entity.organ.Khh;
import com.hnkywl.sts.entity.organ.Nbgs;
import com.hnkywl.sts.service.organ.KhhService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-3-25
 * Time: 下午3:51
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/organ/khh")
public class KhhAction extends SimpleActionSupport {
    private KhhService khhService;
    //开户行名称
    private String khhmc;

    //内部公司ID
    private Long nbgsId;
    //开户行ID
    private Long khhId;
    //开户行
    private Khh khh;

    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows;

    //远程ajax验证的值
    private String validateVal;
    //需要远程ajax验证的属性
    private String validateField;
    //账户全称
    private String qc;
    //账户简称
    private String jc;
    private Long ejzhId;



    @Action("khhList")
    public void khhList() {
        this.renderJson(this.khhService.findKhhList(nbgsId,qc,jc, page, rows));
    }

    @Action("khh_content")
    public String khhContent() {
        if (khhId != null) {
            khh = khhService.findKhhById(khhId);
        } else {
            khh = new Khh();
            Nbgs nbgs = new Nbgs();
            nbgs.setId(nbgsId);
            khh.setNbgs(nbgs);
        }
        return SUCCESS;
    }

    @Action("khhmcList")
    public void khhmcList() {
        this.renderJson(this.khhService.findKhhmc(khhmc,nbgsId, 0, -1));
    }

    @Action("nbgsKhhmcList")
    public void nbgsKhhmcList() {
        this.renderJson(this.khhService.findNbgsKhhmc(nbgsId, 0, -1));
    }



    @Action("save_khh")
    public void savekhh() {
        try {
            this.khhService.saveKhh(khh);
            renderText("{\"statusCode\":\"200\", \"message\":\"添加开户行成功！\", \"operationType\":\"add\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("update_khh")
    public void updatekhh() {
        try {
            this.khhService.updateKhh(khh);
            renderText("{\"statusCode\":\"200\",\"message\":\"修改开户行成功！\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 方法名:     deleteGc
     * 功能描述:      删除数据库工程
     * 输入参数:
     * 异常:      <RuntimeException  Exception>
     * 创建人:     zsp
     * 创建日期:   13-3-28上午11:47
     * 修改人:     zsp
     * 修改日期:   13-3-28上午11:47
     */
    @Action("delete_khh")
    public void deleteKhh() {
        try {
            this.khhService.deleteKhh(khhId);
            renderText("{\"statusCode\":\"200\", \"message\":\"删除开户行成功！\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 远程ajax验证
     */
    @Action("ajax_validate")
    public void ajaxValidate() {
        if (!khhService.ajaxValidate(khhId,nbgsId,validateVal,validateField))
            renderJson("{\"valid\":true}");
        else
            renderJson("{\"valid\":false}");
    }

    //根据当前的公司机构获得下一个排序号
    @Action("get_nextpxh")
    public void getNextPxh() {
        renderText(khhService.findNextPxh(nbgsId).toString());
    }

    @Action("findKhhByNbgsId")
    public void findKhhByNbgsId() {
        renderJson(khhService.findKhhByNbgsId(nbgsId));
    }

    @Action("findKhhByEjzhId")
    public void findKhhByEjzhId() {
        renderJson(khhService.findKhhByEjzhId(ejzhId));
    }



    @Autowired
    public void setKhhService(KhhService khhService) {
        this.khhService = khhService;
    }
    //===========getter=======getter===============================

    public String getQc() {
        return qc;
    }

    public void setQc(String qc) {
        this.qc = qc;
    }

    public String getJc() {
        return jc;
    }

    public void setJc(String jc) {
        this.jc = jc;
    }

    public String getKhhmc() {
        return khhmc;
    }

    public void setKhhmc(String khhmc) {
        this.khhmc = khhmc;
    }

    public Long getNbgsId() {
        return nbgsId;
    }

    public void setNbgsId(Long nbgsId) {
        this.nbgsId = nbgsId;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public Long getKhhId() {
        return khhId;
    }

    public void setKhhId(Long khhId) {
        this.khhId = khhId;
    }

    public Khh getKhh() {
        return khh;
    }

    public void setKhh(Khh khh) {
        this.khh = khh;
    }

    public String getValidateVal() {
        return validateVal;
    }

    public void setValidateVal(String validateVal) {
        this.validateVal = validateVal;
    }

    public String getValidateField() {
        return validateField;
    }

    public void setValidateField(String validateField) {
        this.validateField = validateField;
    }

    public Long getEjzhId() {
        return ejzhId;
    }

    public void setEjzhId(Long ejzhId) {
        this.ejzhId = ejzhId;
    }
}
